package com.zzyl.service.impl;

import cn.hutool.core.bean.BeanUtil;
import cn.hutool.db.PageResult;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.zzyl.base.PageResponse;
import com.zzyl.dto.NursingLevelDto;
import com.zzyl.entity.NursingLevel;
import com.zzyl.entity.NursingProject;
import com.zzyl.mapper.NursingLevelMapper;
import com.zzyl.service.NursingLevelService;
import com.zzyl.vo.NursingLevelPageVo;
import com.zzyl.vo.NursingLevelVo;
import com.zzyl.vo.NursingProjectVo;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.List;

@Service
@RequiredArgsConstructor
public class NursingLevelServiceImpl implements NursingLevelService {

    private final NursingLevelMapper nursingLevelMapper;

    @Override
    public List<NursingLevelVo> listAll() {
        List<NursingLevelVo> nursingLevelVoList = nursingLevelMapper.selectAll();
        return nursingLevelVoList;
    }

    @Override
    public PageResponse<NursingLevelPageVo> listByPage(Integer pageNum, Integer pageSize, String name, Integer status) {
        PageHelper.startPage(pageNum,pageSize);
        Page<NursingLevel> nursingLevels = nursingLevelMapper.selectByPage(name, status);
        PageResponse<NursingLevelPageVo> levelPageVoPageResponse = PageResponse.of(nursingLevels, NursingLevelPageVo.class);
        return levelPageVoPageResponse;
    }

    @Override
    public NursingLevelPageVo getById(Long id) {
        return nursingLevelMapper.selectById(id);
    }

    @Override
    public void add(NursingLevelDto nursingLevelDto) {
        NursingLevel nursingLevel = new NursingLevel();

        nursingLevel.setName(nursingLevelDto.getName());
        nursingLevel.setLplanId(nursingLevelDto.getPlanId());
        nursingLevel.setFee(nursingLevelDto.getFee());
        nursingLevel.setStatus(nursingLevelDto.getStatus());
        nursingLevel.setDescription(nursingLevelDto.getDescription());
        nursingLevel.setRemark(nursingLevelDto.getRemark());

        nursingLevel.setCreateTime(LocalDateTime.now());
        nursingLevel.setUpdateTime(LocalDateTime.now());

        nursingLevelMapper.insert(nursingLevel);
    }

    @Override
    public void update(NursingLevelDto nursingLevelDto) {
        NursingLevel nursingLevel = new NursingLevel();

        nursingLevel.setId(nursingLevelDto.getId());
        nursingLevel.setName(nursingLevelDto.getName());
        nursingLevel.setLplanId(nursingLevelDto.getPlanId());
        nursingLevel.setFee(nursingLevelDto.getFee());
        nursingLevel.setStatus(nursingLevelDto.getStatus());
        nursingLevel.setDescription(nursingLevelDto.getDescription());
        nursingLevel.setRemark(nursingLevelDto.getRemark());

        nursingLevel.setCreateTime(LocalDateTime.now());
        nursingLevel.setUpdateTime(LocalDateTime.now());

        nursingLevelMapper.update(nursingLevel);
    }

    @Override
    public void deleteById(Long id) {
        nursingLevelMapper.deleteById(id);
    }

    @Override
    public void updateByIdAndStatus(Long id, Integer status) {
        NursingLevel nursingLevel = new NursingLevel();
        nursingLevel.setId(id);
        nursingLevel.setStatus(status);
        nursingLevel.setUpdateTime(LocalDateTime.now());
        nursingLevelMapper.updateByIdAndStatus(nursingLevel);
    }
}
